package o;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Build.VERSION;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.StrikethroughSpan;
import android.text.style.TextAppearanceSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.downloadengine.api.SplitTask;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import com.huawei.appmarket.service.appmgr.view.activity.AppManagerProtocol;
import java.lang.ref.WeakReference;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import o.dqw.c;
import o.dwk.h;
import o.ewm.j;
import o.ewm.n;

public class ecb extends AsyncTask<Void, Void, ApkUpgradeInfo> {
    private static ecb ˏ;
    private e ˋ;
    private d ˎ;
    private WeakReference<Activity> ॱ;

    public interface e {
        void ˏ(ApkUpgradeInfo apkUpgradeInfo);
    }

    static class a implements cks {
        private Context ˋ;
        private ApkUpgradeInfo ˎ;
        private e ˏ;

        public a(Context context, ApkUpgradeInfo apkUpgradeInfo, e eVar) {
            this.ˋ = context;
            this.ˎ = apkUpgradeInfo;
            this.ˏ = eVar;
        }

        public void enableNetworking() {
            if (dok.ͺ()) {
                final dwk o_dwk = new dwk();
                dvt.ˏ().ˊ(this.ˎ.ᐝ());
                SessionDownloadTask ˋ = dvt.ˏ().ˋ(this.ˎ.ᐝ());
                if (ˋ == null) {
                    new dqw().ˏ(dqw.ˊ(this.ˎ.ᐝ(), this.ˎ.ॱʽ(), this.ˎ.ʿ() + ""), new c(this) {
                        final /* synthetic */ a ˊ;

                        public void ˋ(SessionDownloadTask sessionDownloadTask) {
                            if (sessionDownloadTask != null) {
                                SplitTask splitTask;
                                if (this.ˊ.ˎ.ॱʽ() == 0) {
                                    splitTask = new SplitTask();
                                    splitTask.ˋ(this.ˊ.ˎ.ˈ());
                                    splitTask.ˊ(this.ˊ.ˎ.ʾ());
                                    splitTask.ˋ(this.ˊ.ˎ.ʻॱ());
                                    splitTask.ˊॱ(this.ˊ.ˎ.ᐝ());
                                    sessionDownloadTask.ˏ(splitTask);
                                }
                                sessionDownloadTask.ˊ(this.ˊ.ˎ.ˈ());
                                sessionDownloadTask.ˏ(this.ˊ.ˎ.ˊᐝ());
                                sessionDownloadTask.ॱॱ(this.ˊ.ˎ.ˊ());
                                sessionDownloadTask.ʼ(this.ˊ.ˎ.ᐝ());
                                sessionDownloadTask.ʽ(this.ˊ.ˎ.ॱᐝ());
                                sessionDownloadTask.ʻ(this.ˊ.ˎ.ʿ());
                                sessionDownloadTask.ॱ(this.ˊ.ˎ.ˏˎ());
                                sessionDownloadTask.ॱ(this.ˊ.ˎ.ॱ());
                                sessionDownloadTask.ॱˊ(this.ˊ.ˎ.ॱʽ());
                                if (this.ˊ.ˋ instanceof Activity) {
                                    sessionDownloadTask.ˊ(dgm.ˎ((Activity) this.ˊ.ˋ));
                                }
                                if (this.ˊ.ˎ.ʼ() > 0) {
                                    List ᐝˊ = sessionDownloadTask.ᐝˊ();
                                    if (!CollectCheck.isEmpty(ᐝˊ)) {
                                        splitTask = (SplitTask) ᐝˊ.get(0);
                                        splitTask.ˏ(this.ˊ.ˎ.ॱॱ());
                                        splitTask.ॱ(this.ˊ.ˎ.ʼ());
                                        splitTask.ˎ(this.ˊ.ˎ.ˈ());
                                        splitTask.ˋ(this.ˊ.ˎ.ʽॱ());
                                    }
                                    sessionDownloadTask.ˊ(this.ˊ.ˎ.ʽॱ());
                                }
                                this.ˊ.ॱ(o_dwk, sessionDownloadTask);
                            }
                        }

                        public void ॱ() {
                            Logger.e("CheckOtaAndUpdataTask", "OTA get bundle fail.");
                        }
                    });
                    return;
                }
                ॱ(o_dwk, ˋ);
                return;
            }
            evk.ˏ(this.ˋ, n.ʹˊ, 0).ˋ();
        }

        private void ॱ(dwk o_dwk, SessionDownloadTask sessionDownloadTask) {
            h hVar = new h();
            hVar.ˏ(new o.ckh.a(this) {
                final /* synthetic */ a ˎ;

                {
                    this.ˎ = r1;
                }

                public void ˏ(AlertDialog alertDialog, com.huawei.appgallery.foundation.ui.framework.widget.dialog.dialogactivity.DialogActivity.a aVar, int i) {
                    if (-1 == i) {
                        cjk.ˎ().ˋ(this.ˎ.ˋ, new AppManagerProtocol().ˎ());
                    }
                }
            });
            hVar.ˊ(this.ˋ);
            hVar.ˏ(sessionDownloadTask);
            o_dwk.ˏ(false, hVar);
            if (dvr.ˏ(this.ˋ, true)) {
                cjk.ˎ().ˋ(this.ˋ, new AppManagerProtocol().ˎ());
            }
        }

        public void upgrade() {
            if (this.ˏ != null) {
                this.ˏ.ˏ(this.ˎ);
            }
        }

        public void ˋ() {
        }
    }

    public interface d {
        void ˋ();
    }

    protected /* synthetic */ Object doInBackground(Object[] objArr) {
        return ॱ((Void[]) objArr);
    }

    protected /* synthetic */ void onPostExecute(Object obj) {
        ˊ((ApkUpgradeInfo) obj);
    }

    public ecb(Activity activity, e eVar) {
        this.ॱ = new WeakReference(activity);
        this.ˋ = eVar;
    }

    public void ˋ(d dVar) {
        this.ˎ = dVar;
    }

    public static ecb ॱ() {
        return ˏ;
    }

    public static void ˋ(ecb o_ecb) {
        ˏ = o_ecb;
    }

    public static boolean ˎ(Activity activity, e eVar) {
        if (ActivityUtil.isAcitivtyNotValid(activity)) {
            Logger.ˎ("CheckOtaAndUpdataTask", "activity have finished.do not check ota update.");
            return false;
        }
        ApkUpgradeInfo ॱ;
        String packageName = activity.getPackageName();
        ApkUpgradeInfo ˎ = dss.ॱ().ˎ(packageName, false, 0);
        if (ˎ == null) {
            ॱ = dss.ॱ().ॱ(packageName, false, 0);
        } else {
            ॱ = ˎ;
        }
        if (ॱ == null) {
            return false;
        }
        if (ॱ.ˋᐝ() != 1 && dss.ॱ().ˊ(packageName)) {
            return false;
        }
        long parseLong = Long.parseLong(new SimpleDateFormat("yyyyMMdd", Locale.US).format(new Date()));
        euf ˎ2 = euf.ˎ();
        long ॱ2 = ˎ2.ॱ("lastCheckDate", 0);
        int i = 1 == ॱ.ˋᐝ() ? 1 : 0;
        if (i == 0) {
            i = parseLong >= ॱ2 + 7 ? 1 : 0;
        }
        if (i == 0) {
            return false;
        }
        ˏ(activity, ॱ, eVar);
        ˎ2.ˎ("lastCheckDate", parseLong);
        return true;
    }

    private static void ॱ(ApkUpgradeInfo apkUpgradeInfo, TextView textView) {
        if (textView != null) {
            if (apkUpgradeInfo.ʼ() > 0) {
                Object ˊ = epw.ˊ(apkUpgradeInfo.ʻॱ());
                CharSequence spannableString = new SpannableString(ˊ);
                spannableString.setSpan(new StrikethroughSpan(), 0, ˊ.length(), 33);
                spannableString.setSpan(new TextAppearanceSpan("HwChinese-medium", 0, (int) textView.getTextSize(), null, null), 0, spannableString.length(), 33);
                textView.setText(spannableString);
                return;
            }
            textView.setVisibility(8);
        }
    }

    private static long ˎ(ApkUpgradeInfo apkUpgradeInfo) {
        long ʻॱ = apkUpgradeInfo.ʻॱ();
        if (apkUpgradeInfo.ʼ() > 0) {
            return apkUpgradeInfo.ʼ();
        }
        return ʻॱ;
    }

    private static void ˏ(Activity activity, ApkUpgradeInfo apkUpgradeInfo, e eVar) {
        CharSequence string;
        Object obj;
        CharSequence string2;
        if (TextUtils.isEmpty(apkUpgradeInfo.ʼॱ())) {
            string = activity.getString(n.ߵ);
        } else {
            Object ʼॱ = apkUpgradeInfo.ʼॱ();
        }
        String str = "";
        str = "";
        str = "";
        CharSequence ˊ = epw.ˊ(ˎ(apkUpgradeInfo));
        CharSequence ʽ = apkUpgradeInfo.ʽ();
        CharSequence ˊ2 = apkUpgradeInfo.ˊ();
        CharSequence string3 = activity.getString(n.ʻㆍ);
        String string4 = activity.getString(n.ʻᶥ);
        if (1 == apkUpgradeInfo.ˋᐝ()) {
            obj = 1;
            string2 = activity.getString(n.ʻꓸ);
        } else {
            obj = null;
            Object string5 = activity.getString(n.ʻꜞ);
        }
        View inflate = LayoutInflater.from(activity).inflate(ewm.h.ꞌॱ, null);
        ˎ((ImageView) inflate.findViewById(j.ᐧˎ));
        TextView textView = (TextView) inflate.findViewById(j.ˈˊ);
        TextView textView2 = (TextView) inflate.findViewById(j.ˉˑ);
        TextView textView3 = (TextView) inflate.findViewById(j.ˊʽ);
        TextView textView4 = (TextView) inflate.findViewById(j.ᐝߵ);
        TextView textView5 = (TextView) inflate.findViewById(j.ʽॱ);
        textView.setText(string);
        textView2.setText(ʽ);
        textView3.setText(ˊ);
        textView4.setText(ˊ2);
        ॱ(apkUpgradeInfo, textView5);
        ˏ(inflate);
        cku ˏ = cku.ˏ(activity, cku.class, string3, null);
        ˏ.ˊ(inflate);
        ˏ.ॱ(-1, (CharSequence) string4);
        ˏ.ॱ(-2, string2);
        if (obj != null) {
            ˏ.setCancelable(false);
        }
        ˊ(activity, ˏ);
        ˏ.ॱ(new a(activity, apkUpgradeInfo, eVar));
        ˏ.ˋ((Context) activity, "OTADialog");
    }

    private static void ˊ(Context context, cku o_cku) {
        int ॱ = azc.ˎ().ॱ();
        if (ॱ >= 11 && ॱ < 17) {
            o_cku.ॱ(-1, new cku.c());
        }
    }

    private static void ˎ(ImageView imageView) {
        if (imageView != null) {
            if (azc.ˎ().ॱ() < 11 || azc.ˎ().ॱ() >= 17) {
                imageView.setVisibility(8);
            }
        }
    }

    private static void ˏ(View view) {
        try {
            ScrollView scrollView = (ScrollView) view.findViewById(j.ʻꜝ);
            if (VERSION.SDK_INT >= 22) {
                int ˎ = ewb.ˎ((Activity) view.getContext());
                scrollView.setPadding(ˎ, 0, ˎ, 0);
            }
        } catch (Exception e) {
            Logger.e("CheckOtaAndUpdataTask", e.toString());
        }
    }

    public Activity ˏ() {
        return ˊ();
    }

    protected void onPreExecute() {
        super.onPreExecute();
    }

    protected ApkUpgradeInfo ॱ(Void... voidArr) {
        Logger.ˎ("CheckOtaAndUpdataTask", "CheckOtaAndUpdataTask doInBackground");
        Context ˊ = ˊ();
        if (ˊ == null) {
            return null;
        }
        String packageName = ˊ.getPackageName();
        ApkUpgradeInfo ˎ = dss.ॱ().ˎ(packageName, false, 0);
        if (ˎ == null) {
            ˎ = dss.ॱ().ॱ(packageName, false, 0);
        }
        if (ˎ == null) {
            return dss.ॱ().ˎ(ˊ, packageName, 0, 1);
        }
        return ˎ;
    }

    protected void ˊ(ApkUpgradeInfo apkUpgradeInfo) {
        Context ˊ = ˊ();
        if (ˊ != null) {
            if (apkUpgradeInfo != null) {
                Logger.ˎ("CheckOtaAndUpdataTask", "check store client update success!" + apkUpgradeInfo.ʿ() + ",version:" + apkUpgradeInfo.ʽ());
                ˎ(apkUpgradeInfo, this.ˋ);
            } else {
                evk.ˏ(ˊ, n.ˌʽ, 0).ˋ();
            }
            if (this.ˎ != null) {
                this.ˎ.ˋ();
            }
        }
    }

    private void ˎ(ApkUpgradeInfo apkUpgradeInfo, e eVar) {
        if (this.ॱ != null) {
            Activity ˊ = ˊ();
            if (ˊ != null) {
                ˏ(ˊ, apkUpgradeInfo, eVar);
                eby.ˎ().ˋ(false);
                euf.ˎ().ˋ("client_update_red_point_version", apkUpgradeInfo.ʽ());
            }
        }
    }

    private Activity ˊ() {
        if (this.ॱ == null) {
            return null;
        }
        return (Activity) this.ॱ.get();
    }
}
